package com.linwen.excise.algorithm.贪心;

import java.util.Arrays;
import java.util.Scanner;


/**
 * 6 3
 * 10 5 3 7 2 1
 * */
public class _06 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] ni = new int[n];
        for (int i = 0; i < n; i++) {
            ni[i] = scanner.nextInt();
        }
        scanner.close();
        System.out.println(greedStrategy(ni,m));
    }

    private static int greedStrategy(int[] ni, int m) {
        Arrays.sort(ni);
        if(m>ni.length){// 作业数小于机器数，直接返回作业数最大时间
            return ni[ni.length-1];
        }
        int niIndex = ni.length-1;
        int[] mt = new int[m];
        int zeroCount = 0;
        int result = 0;
        while (niIndex>=0||zeroCount!=m){
            for (int i = 0; i <m; i++) {
                if(mt[i]==0){// 检查是否可分配任务
                    // 分配任务
                    if(niIndex>=0){
                        mt[i] = ni[niIndex];
                        niIndex--;
                        zeroCount += zeroCount == 0 ? 0 : -1;
                    }// 跳过
                }
                mt[i]--;
                if(mt[i]==0){
                    zeroCount++;
                }
            }
            result++;
        }
        return result;
    }
}
